package com.tuanzi.loan.web.bean.application;

import com.tuanzi.loan.business.entity.application.LoanApplicationExportGroupPage;
import com.tuanzi.loan.business.service.application.LoanApplicationExportGroupPageService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.web.configuration.JSFInfoBean;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;

/**
 * @Auther: hequnayu
 * @Date: 2019/7/30 14:32
 * @Description:
 */
@Debug
@Component
@ViewScoped
public class LoanApplicationExportGroupPageInfoBean extends JSFInfoBean<LoanApplicationExportGroupPage> {

    private static final long serialVersionUID = -2563168267909232821L;
    @Autowired
    private LoanApplicationExportGroupPageService bannerPageService;

    @PostConstruct
    private void init() {
        String id = getParamFromRequest("id");
        if (StringUtils.isNotBlank(id)) {
            $ = bannerPageService.findOne(NumberUtils.toLong(id));
        } else {
            $ = new LoanApplicationExportGroupPage();
            changeStatusToAdd();
        }
    }

    public void onSave() {
        if(StringUtils.isEmpty($.getName())) {
            addFiledMessage("作用页面名称不能为空");
            return;
        }
        $ = bannerPageService.saveOrUpdate($);
        changeStatusToView();
        addSuccessfullyMessage();
    }


}
